package org.example.udemo1.controller;

import jakarta.servlet.http.HttpSession;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/user1")
@RestController
public class UserController {

    @RequestMapping("/login1")
    public Boolean login(String name, String password, HttpSession session){
        //1.校验参数形式
        //2.从数据库中校验账号和密码是否正确,但是还未学,暂且写死
        //3.如果正确,存储session,返回true
        if(!StringUtils.hasLength(name) || !StringUtils.hasLength(password)){
            System.out.println("false1");
            return false;
        }
        if("admin".equals(name) && "admin".equals(password)){
            //账号密码都正确
            //session的内容,取决于后面需要从session中获取什么
            session.setAttribute("userName",name);
            System.out.println("true");
            return true;
        }
        System.out.println("false2");
        return false;
    }
}
